package com.yytek.nmp.controller;

import java.util.List;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yytek.common.log.annotation.Log;
import com.yytek.common.log.enums.BusinessType;
import com.yytek.common.security.annotation.RequiresPermissions;
import com.yytek.nmp.domain.IotServiceHistory;
import com.yytek.nmp.service.IIotServiceHistoryService;
import com.yytek.common.core.web.controller.BaseController;
import com.yytek.common.core.web.domain.AjaxResult;
import com.yytek.common.core.utils.poi.ExcelUtil;
import com.yytek.common.core.web.page.TableDataInfo;

/**
 * 服务记录Controller
 * 
 * @author yytek-iot
 * @date 2022-07-13
 */
@Api(value = "服务记录控制器", tags = {"服务记录管理"})
@RestController
@RequestMapping("/serviceHistory")
public class IotServiceHistoryController extends BaseController
{
    @Autowired
    private IIotServiceHistoryService iotServiceHistoryService;

    /**
     * 查询服务记录列表
     */
    @ApiOperation("查询服务记录列表")
    @GetMapping("/list")
    public TableDataInfo list(IotServiceHistory iotServiceHistory)
    {
        startPage();
        List<IotServiceHistory> list = iotServiceHistoryService.selectIotServiceHistoryList(iotServiceHistory);
        return getDataTable(list);
    }

    /**
     * 导出服务记录列表
     */
    @ApiOperation("导出服务记录列表")
    @RequiresPermissions("nmp:history:export")
    @Log(title = "服务记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotServiceHistory iotServiceHistory)
    {
        List<IotServiceHistory> list = iotServiceHistoryService.selectIotServiceHistoryList(iotServiceHistory);
        ExcelUtil<IotServiceHistory> util = new ExcelUtil<IotServiceHistory>(IotServiceHistory.class);
        util.exportExcel(response, list, "服务记录数据");
    }

    /**
     * 获取服务记录详细信息
     */
    @ApiOperation("获取服务记录详细信息")
    @RequiresPermissions("nmp:history:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(iotServiceHistoryService.selectIotServiceHistoryById(id));
    }

    /**
     * 新增服务记录
     */
    @ApiOperation("新增服务记录")
    @RequiresPermissions("nmp:history:add")
    @Log(title = "服务记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IotServiceHistory iotServiceHistory)
    {
        return toAjax(iotServiceHistoryService.insertIotServiceHistory(iotServiceHistory));
    }

    /**
     * 修改服务记录
     */
    @ApiOperation("修改服务记录")
    @RequiresPermissions("nmp:history:edit")
    @Log(title = "服务记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IotServiceHistory iotServiceHistory)
    {
        return toAjax(iotServiceHistoryService.updateIotServiceHistory(iotServiceHistory));
    }

    /**
     * 删除服务记录
     */
    @ApiOperation("删除服务记录")
    @RequiresPermissions("nmp:history:remove")
    @Log(title = "服务记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(iotServiceHistoryService.deleteIotServiceHistoryByIds(ids));
    }
}
